<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: #f00;
        }
    </style>
</head>
<body>
    <button id="btn">切换</button>
    <div id="box"></div>
    <script>
        let oBtn = document.getElementById('btn');
        let oBox = document.getElementById('box');
        // 元素.事件
        // onclick 鼠标左键单击
        // ondoubleclick 双击
        // onmouseover 鼠标移入
        // onmouseout 鼠标移出
        // 元素.属性名
        let onOff = true;
        oBtn.onclick = function(){
            if(onOff){
                oBox.style.display = 'none';
            }else{
                oBox.style.display = 'block';
            }
            onOff = !onOff;
            // console.log(this.id);
        }
    </script>
</body>
</html>